const nTube1Globals = {
    globalsVersion: "04-07-2020",
    loadMediaMetadata: function(VIDEO_ID, jsonObject, clientType) {
        if (VIDEO_ID === null || VIDEO_ID === undefined) return;
        if (clientType === null || clientType === undefined) clientType = "ntube.desktop";
        if (jsonObject["apiVersion"] && jsonObject["apiVersion"] >= 2) { /* TODO: once nTube 1.6/1.7 is a thing. */ }
        else {
            if (window.MediaMetadata && 'mediaSession' in navigator) {
                var pp = id("_primary_player");
                if (pp === null || pp === undefined) pp = id("__video_player");
                if (pp.tagName === "DIV") {
                    pp = pp.children[0];
                }
                navigator.mediaSession.metadata = new MediaMetadata({
                    title: jsonObject.metadata.title,
                    artist: jsonObject.metadata.author,
                    album: (clientType === "ntube.embedded" ? "nTube Embedded." : "nTube."),
                    artwork: [
                        /*{
                            src: "http://i.ytimg.com/vi/" + VIDEO_ID + "/sddefault.jpg",
                            sizes: "640x480",
                        },*/
                        {
                            src: "http://i.ytimg.com/vi/" + VIDEO_ID + "/hqdefault.jpg",
                            sizes: "480x360",
                        },
                        {
                            src: "http://i.ytimg.com/vi/" + VIDEO_ID + "/mqdefault.jpg",
                            sizes: "320x180",
                        },
                        {
                            src: "http://i.ytimg.com/vi/" + VIDEO_ID + "/default.jpg",
                            sizes: "120x90",
                        }
                    ],
                });
                navigator.mediaSession.setActionHandler('play', function() {
                    if ('mainPlayer' in window) {
                        mainPlayer.play();
                    }else {
                        pp.play();
                    }
                    navigator.mediaSession.playbackState = "playing";
                });
                navigator.mediaSession.setActionHandler('pause', function() {
                    if ('mainPlayer' in window) {
                        mainPlayer.pause();
                    }else {
                        pp.pause();
                    }
                    navigator.mediaSession.playbackState = "paused";
                });
                navigator.mediaSession.setActionHandler('seekbackward', function() {
                    if ('mainPlayer' in window) {
                        mainPlayer.seek(mainPlayer.getTime() - 5);
                    }else {
                        pp.currentTime -= 5;
                    }
                });
                navigator.mediaSession.setActionHandler('seekforward', function() {
                    if ('mainPlayer' in window) {
                        mainPlayer.seek(mainPlayer.getTime() + 5);
                    }else {
                        pp.currentTime += 5;
                    }
                });
                if (jsonObject["related"] && jsonObject["related"].length > 0) {
                    const i0 = jsonObject["related"][0];
                    if (i0["isUpNext"] === true) {
                        navigator.mediaSession.setActionHandler('nexttrack', function() {
                            if (jsonObject["playlist"]) {
                                if (jsonObject["playlist"]["next"]) {
                                    if (window.loadVideo) {
                                        window.loadVideo(jsonObject.playlist.next.link);
                                    }else {
                                        window.location = jsonObject.playlist.next.link;
                                    }
                                    return;
                                }
                            }
                            window.location = i0.link;
                            return;
                        });
                    }
                }
            }
        }
    },
    generateSettings: function() {
        function __allowWebM() {
            if (supportsVideoType) {
                return supportsVideoType("vp9") === "probably";
            }
            return true;
        }
        const REQUEST_OPTIONS = {
            preferredQuality: -1,
            av1_action: "def",
            allowWebM: __allowWebM(),
            remove30FPSVideos: false,
            dashJSSetQualityOnLoad: false,
            enableHDR: false,
        };
        return null;
    }
};
window.nTube1Globals = nTube1Globals;
if (window.nTube && (window.nTube.versionInt >= 1.5 && window.nTube.versionInt <= 1.6)) {
    window.nTube.Globals = nTube1Globals;
}